OTP generater
import random
import string
def generate_otp(length=6, use_alphanumeric=False):
if use_alphanumeric:
characters = string.ascii_uppercase + string.digits
else:
characters = string.digits
otp = ''.join(random.choices(characters, k=length))
return otp
def main():
print("--- OTP Generator ---")
try:
length = int(input("Enter OTP length (e.g. 6): "))
use_alpha = input("Include letters? (y/n): ").strip().lower() == 'y'
otp = generate_otp(length, use_alphanumeric=use_alpha)
print(f"Your OTP is: {otp}")
except ValueError:
print("Invalid input. Please enter a number.")
if __name__ == "__main__":
main()
Code output
--- OTP Generator ---
Enter OTP length (e.g. 6): 6
Include letters? (y/n): n
Your OTP is: 927405